package com.ywxx.dyhelper.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Switch;

import com.ywxx.dyhelper.R;
import com.ywxx.dyhelper.base.BaseAcitivity;
import com.ywxx.dyhelper.model.TaskConfig;
import com.ywxx.dyhelper.utils.ConstValues;
import com.ywxx.dyhelper.widget.NumberAddSubView;

/**
 * 精准引流
 */
public class PreciseDrainageActivity extends BaseAcitivity
{

    private NumberAddSubView labNum;
    private NumberAddSubView labOperNum;
    private NumberAddSubView labFollowNum;
    private NumberAddSubView labFansNum;
    private NumberAddSubView labLikeNum;
    private NumberAddSubView labVlogNum;

    private Switch sw_Lately;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_precise_drainage);
        InitUI();
        DataToUI();

    }

    @Override
    protected void InitUI()
    {
        InitTitle();
        labNum = findViewById(R.id.labNum);
        labOperNum = findViewById(R.id.labOperNum);
        labFollowNum = findViewById(R.id.labFollowNum);
        labFansNum = findViewById(R.id.labFansNum);
        labLikeNum = findViewById(R.id.labLikeNum);
        labVlogNum = findViewById(R.id.labVlogNum);
        sw_Lately = findViewById(R.id.sw_Lately);

        labNum.setMaxValue(8);
        labNum.setMinValue(1);
        labNum.setValue(4);

        labOperNum.setValue(8000);
        labOperNum.setMaxValue(60000);
        labOperNum.setSeekNum(500);

        labFollowNum.setValue(500);
        labFollowNum.setMaxValue(36000);
        labFollowNum.setSeekNum(100);

        labFansNum.setValue(500);
        labFansNum.setMaxValue(100000000);
        labFansNum.setSeekNum(100);

        labVlogNum.setValue(20);
        labVlogNum.setMaxValue(36000);
        labVlogNum.setSeekNum(10);

        labLikeNum.setValue(100);
        labLikeNum.setMaxValue(100000000);
        labLikeNum.setSeekNum(5);

        llStart.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                appconfig = new TaskConfig();
                appconfig.runtime = labNum.getValue();
                appconfig.oprtime = labOperNum.getValue();
                appconfig.follow_num = labFollowNum.getValue();
                appconfig.fans_num = labFansNum.getValue();
                appconfig.vlog_num = labVlogNum.getValue();
                appconfig.like_num = labLikeNum.getValue();
                appconfig.lately = sw_Lately.isChecked();

                ConstValues.SaveValue(PreciseDrainageActivity.this, "runtime" + TaskType, appconfig.runtime);
                ConstValues.SaveValue(PreciseDrainageActivity.this, "opertime" + TaskType, appconfig.oprtime);
                ConstValues.SaveValue(PreciseDrainageActivity.this, "follow_num" + TaskType, appconfig.follow_num);
                ConstValues.SaveValue(PreciseDrainageActivity.this, "fans_num" + TaskType, appconfig.fans_num);
                ConstValues.SaveValue(PreciseDrainageActivity.this, "vlog_num" + TaskType, appconfig.vlog_num);
                ConstValues.SaveValue(PreciseDrainageActivity.this, "vlog_like" + TaskType, appconfig.like_num);
                ConstValues.SaveValue(PreciseDrainageActivity.this, "lately" + TaskType, appconfig.lately);

                StartTaskServer(TaskType);
            }
        });

    }

    @Override
    protected void DataToUI()
    {
        int runtime = ConstValues.getIntValue(this, "runtime" + TaskType, 4);
        int opertime = ConstValues.getIntValue(this, "opertime" + TaskType, 6000);
        int follow = ConstValues.getIntValue(this, "follow_num" + TaskType, 500);
        int fans = ConstValues.getIntValue(this, "fans_num" + TaskType, 500);
        int vlog = ConstValues.getIntValue(this, "vlog_num" + TaskType, 20);
        int like = ConstValues.getIntValue(this, "vlog_like" + TaskType, 100);
        boolean lately = ConstValues.getBooleanValue(this, "lately" + TaskType, false);

        labNum.setValue(runtime);
        labOperNum.setValue(opertime);
        labFollowNum.setValue(follow);
        labFansNum.setValue(fans);
        labVlogNum.setValue(vlog);
        labLikeNum.setValue(like);
        sw_Lately.setChecked(lately);
    }
}